package cn.bonoon.controllers.place;

import cn.bonoon.entities.PlaceEntity;
import cn.bonoon.kernel.annotations.Transform;
import cn.bonoon.kernel.annotations.TransformField;
import cn.bonoon.kernel.annotations.WriteModel;
import cn.bonoon.kernel.support.models.ObjectEditor;
import cn.bonoon.kernel.util.BoolType;
import cn.bonoon.kernel.web.annotations.AjaxTreeLoader;
import cn.bonoon.kernel.web.annotations.AutoDataLoader;
import cn.bonoon.kernel.web.annotations.components.AsCheckbox;
import cn.bonoon.kernel.web.annotations.components.AsComboTree;
import cn.bonoon.kernel.web.annotations.components.AsNumberBox;
import cn.bonoon.kernel.web.annotations.components.AsSelector;
import cn.bonoon.kernel.web.annotations.components.AsTextArea;
import cn.bonoon.kernel.web.annotations.form.FormEditor;
import cn.bonoon.kernel.web.annotations.form.PropertyEditor;
import cn.bonoon.kernel.web.annotations.form.PropertyHelper;
import cn.bonoon.kernel.web.annotations.form.PropertyHelper.HelperType;
import cn.bonoon.kernel.web.annotations.form.PropertyUpdate;

@Transform
@FormEditor(2)
public class PlaceEditor extends ObjectEditor implements PlaceDefine {

	/**
	 * 
	 */
	private static final long serialVersionUID = -2280975552849152880L;

	@PropertyEditor(name = "上级地区", value = 3)
	@AsComboTree
	@TransformField(readable = false, writeIgnoreNull = true)
	@AutoDataLoader(PlaceEntity.class)
	@AjaxTreeLoader
	private Long parent;

	@PropertyEditor(value = 2, required = true)
	private String name;

	@PropertyUpdate(colspan = 1, name = "原上级地区", value = 1, readonly = BoolType.TRUE)
	@TransformField(value = "parent.fullName", writable = WriteModel.NONE)
	private String parentName;
	/**
	 * 地区编码
	 */
	@PropertyEditor(value = 0, required = true, colspan = 1, width = 200)
	@PropertyHelper(value = "地区行政编码，如：广州为440100000000", type = HelperType.DIRECT)
	private String code;

	/**
	 * <pre>
	 * 地区名的简称,如,广东简称为粤等.
	 * 注意,如果是市级,并且市级没有定义简称,则会使用上一级的简称,直接找到最近一级的简称为止.
	 * 如果都没有,则简称为空.
	 * </pre>
	 */
	@PropertyEditor(value = 13, width = 60, colspan = 1)
	@PropertyHelper(value = "地区名简称,如,广东简称为粤等，如果为空，则自动使用上级地区的简称", type = HelperType.DIRECT)
	private String abbreviationName;

	/**
	 * 地区英文简称（如广州 ”A”）
	 */
	@PropertyEditor(value = 14, width = 60, colspan = 1)
	@PropertyHelper(value = "地区英文简称（如广州 ”A”），如果为空，则自动使用上级地区的简称", type = HelperType.DIRECT)
	private String shortCode;

	@PropertyEditor(15)
	@AsSelector
	private Integer level;

	@PropertyEditor(16)
	@AsNumberBox
	private Long population;

	@PropertyEditor(value = 17, colspan = 1)
	@AsCheckbox("是")
	@PropertyHelper(value = "如果该地区不可用，下级地区也都不可用！", type = HelperType.DIRECT)
	private boolean disabled;

	@PropertyEditor(20)
	@AsNumberBox
	private Double longitude;

	@PropertyEditor(21)
	@AsNumberBox
	private Double latitude;

	@PropertyEditor(value = 60, colspan = 1)
	@AsTextArea
	private String remark;

	public String getRemark() {
		return remark;
	}

	public void setRemark(String remark) {
		this.remark = remark;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getAbbreviationName() {
		return abbreviationName;
	}

	public void setAbbreviationName(String abbreviationName) {
		this.abbreviationName = abbreviationName;
	}

	public String getShortCode() {
		return shortCode;
	}

	public void setShortCode(String shortCode) {
		this.shortCode = shortCode;
	}

	public String getCode() {
		return code;
	}

	public void setCode(String code) {
		this.code = code;
	}

	public Integer getLevel() {
		return level;
	}

	public void setLevel(Integer level) {
		this.level = level;
	}

	public Long getParent() {
		return parent;
	}

	public void setParent(Long parent) {
		this.parent = parent;
	}

	public Double getLongitude() {
		return longitude;
	}

	public void setLongitude(Double longitude) {
		this.longitude = longitude;
	}

	public Double getLatitude() {
		return latitude;
	}

	public void setLatitude(Double latitude) {
		this.latitude = latitude;
	}

	public boolean isDisabled() {
		return disabled;
	}

	public void setDisabled(boolean disabled) {
		this.disabled = disabled;
	}

	public Long getPopulation() {
		return population;
	}

	public void setPopulation(Long population) {
		this.population = population;
	}

	public String getParentName() {
		return parentName;
	}

	public void setParentName(String parentName) {
		this.parentName = parentName;
	}

}
